package com.ayoka.mvp;

import com.ayoka.R;
import com.ayoka.base.BasePresenter;
import com.ayoka.base.IBaseView;
import com.ayoka.bean.BaseResponse;
import com.ayoka.http.API;
import com.ayoka.http.OkHttpListener;
import com.ayoka.mvp.CourseEstimateMVP.CourseEstimateModel.CourseEstimateDescriptionBean;
import com.ayoka.mvp.CourseEstimateMVP.CourseEstimateModel.ResponseCourseEstimateBean;
import com.ayoka.mvp.CourseEstimateMVP.CourseEstimateModel.CourseEstimateReportBean;
import com.jcp.baselibrary.utils.UIUtils;

import java.io.Serializable;
import java.util.List;

/**
 * Created by gabriel on 2017/3/5.
 */

public interface CourseEstimateMVP {

    interface CourseEstimateModel {

        class CourseEstimateDescriptionBean {
            public long ID;
            public long CoursePackageID;
            public String Title;
            public String Img;
            public String Descp;
            public int MaxScore;
            public int QuestionCount;
            public int LimitTime;
            public int Participants;
            public int AssessmentResultType;
        }

        class ResponseCourseEstimateBean {
            public long record_id;
            public CourseEstimateDetailBean testing_info;
        }

        class CourseEstimateDetailBean implements Serializable{
            public long ID;
            public String Title;
            public String Descp;
            public List<CourseEstimateQuestionBean> Questions;
            public int QuestionCount;
            public int LimitTime;
            public int Participants;
        }


        class CourseEstimateQuestionBean implements Serializable{
            public long ID;
            public long TestingID;
            public long FactorGroupID;
            public int QuestionIndex;
            public String Question;
            public String _Options;
            public List<QuestionOption> Options;
        }

        class QuestionOption implements Serializable{

            public String Option;
            public int Score;
            public boolean isSelected;
        }

        class CourseEstimateReportBean {
            public int assessment_type;
            public CourseEstimateRecordBean testing_record;
            public CourseEstimateResultBean testing_result_assessment;
        }

       class CourseEstimateRecordBean {
            public long ID;
            public long Uid;
            public long TestingID;
            public CourseEstimateInformationBean TestingInfo;
            public int TotalScore;
            public double Price;
            public int DockedSeconds;
            public String CreateDate;
            public String LastUpdate;

        }

        class CourseEstimateResultBean {
            public long ID;
            public long TestingID;
            public long FactorGroupID;
            public int StartScore;
            public int EndScore;
            public String Assessment;
            public String CreateDate;
            public String LastUpdate;
        }

        class CourseEstimateInformationBean {
            public long ID;
            public String Title;
            public int QuestionCount;
            public int LimitTime;
            public int MaxScore;
            public String EvaluationNotes;
        }
    }

    interface ICourseEstimateView extends IBaseView {

        void configCourseEstimateDescriptionData(CourseEstimateDescriptionBean courseEstimateDescriptionBean);

        void configCourseEstimateDetailData(ResponseCourseEstimateBean data);

        void onSubmitCourseEstimateCallback(boolean isSuccess, int recordId);

        void configCourseEstimateReportData(CourseEstimateReportBean courseEstimateReportBean);

    }

    class CourseEstimatePresenter extends BasePresenter<ICourseEstimateView> {

        public void getCourseEstimateDescriptionData(long coursePackageId) {
            mViewRef.get().showWaitDialog(UIUtils.getString(R.string.loading));
            API.getCourseEstimateDescriptionData(this, coursePackageId, new OkHttpListener<BaseResponse<CourseEstimateDescriptionBean>>() {
                @Override
                public void onSuccess(BaseResponse<CourseEstimateModel.CourseEstimateDescriptionBean> response) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().configCourseEstimateDescriptionData(response.data);
                }

                @Override
                public void onFailure(int errorCode, String errorMessage) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().showToast(errorMessage);
                }
            });
        }

        public void getCourseEstimateDetailData(long estimateId) {
            mViewRef.get().showWaitDialog(UIUtils.getString(R.string.loading));
            API.getCourseEstimateDetailData(this, estimateId, new OkHttpListener<BaseResponse<ResponseCourseEstimateBean>>() {
                @Override
                public void onSuccess(BaseResponse<ResponseCourseEstimateBean> response) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().configCourseEstimateDetailData(response.data);
                }

                @Override
                public void onFailure(int errorCode, String errorMessage) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().showToast(errorMessage);
                }
            });
        }

        public void submitCourseEstimate() {
            mViewRef.get().onSubmitCourseEstimateCallback(true, 1);
        }

        public void getCourseEstimateReportData(long recordId) {
            mViewRef.get().showWaitDialog(UIUtils.getString(R.string.loading));
            API.getCourseEstimateReportData(this, recordId, new OkHttpListener<BaseResponse<CourseEstimateReportBean>>() {
                @Override
                public void onSuccess(BaseResponse<CourseEstimateReportBean> response) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().configCourseEstimateReportData(response.data);
                }

                @Override
                public void onFailure(int errorCode, String errorMessage) {
                    if (!isAttached()) return;
                    mViewRef.get().hideWaitDialog();
                    mViewRef.get().showToast(errorMessage);
                }
            });
        }

    }

}
